package com.obrempon.credit.market.ui.fragment

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.graphics.Typeface
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import com.obrempon.credit.market.ObremponApp
import com.obrempon.credit.market.R
import com.obrempon.credit.market.common.CommonFragment
import com.obrempon.credit.market.configs.ObremponApiPath
import com.obrempon.credit.market.configs.ObremponApiUrl.addCommonParams
import com.obrempon.credit.market.databinding.ObremponAuthStepOcrFragmentBinding
import com.obrempon.credit.market.event.ObremponEventPointType
import com.obrempon.credit.market.httptest.api.UpdateImageApi
import com.obrempon.credit.market.request.HttpHelper
import com.obrempon.credit.market.ui.activity.ObremponAuthStepsAct
import com.obrempon.credit.market.ui.activity.ObremponCameraOcrAct
import com.obrempon.credit.market.ui.dialog.ObremponPhotoDialog
import com.obrempon.credit.market.ui.dialog.ObremponSubmitSuccessDialog
import com.obrempon.credit.market.ui.popupwindow.ObremponOcrTypePopupwindow
import com.obrempon.credit.market.utils.ObremponDensityUtil
import com.obrempon.credit.market.utils.ObremponImageUtil
import com.obrempon.credit.market.utils.helper.ObremponConfigsHelper
import com.obrempon.credit.market.utils.imgcovert.ImageConvert
import com.obrempon.credit.market.utils.log.ObremponLogger
import com.obrempon.module.easyhttp.config.IRequestApi
import com.obrempon.module.easyhttp.listener.OnUpdateListener
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.json.JSONObject
import pub.devrel.easypermissions.AppSettingsDialog
import pub.devrel.easypermissions.EasyPermissions

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/21 13:40
 * @Annotation：认证流程 - 身份证、护照、驾驶证
 */
class ObremponAuthStepOcrFragment(): CommonFragment(),EasyPermissions.PermissionCallbacks,EasyPermissions.RationaleCallbacks  {
    lateinit var binding: ObremponAuthStepOcrFragmentBinding

    private var stepItem: JSONObject? = null
    private var eventRemark = ""

    private val ocrTypeList = arrayListOf<JSONObject>()
    private val typeTitleList = arrayListOf(
        "${R.mipmap.obrempon_auth_step_ocr_id_card_icon},${ObremponApp.app.getString(R.string.obrempon_auth_step_ocr_type_id_card)},IDCARD",
        "${R.mipmap.obrempon_auth_step_ocr_passport_icon},${ObremponApp.app.getString(R.string.obrempon_auth_step_ocr_type_passport)},PASSPORT",
        "${R.mipmap.obrempon_auth_step_ocr_driving_license_icon},${ObremponApp.app.getString(R.string.obrempon_auth_step_ocr_type_driving_license)},DRIVING",
        "${R.mipmap.obrempon_auth_step_ocr_election_card_icon},${ObremponApp.app.getString(R.string.obrempon_auth_step_ocr_type_election_card)},ELECTIONCARD",
        "${R.mipmap.obrempon_auth_step_ocr_no_documents_icon},${ObremponApp.app.getString(R.string.obrempon_auth_step_ocr_type_no_documents)},NONE"
    )
    private var ocrTypePopupwindow: ObremponOcrTypePopupwindow? = null
    private var selectTypeItem: JSONObject? = null

    private var photoDialog: ObremponPhotoDialog? = null

    //是否选中删除信息,默认选中
    private var isSelectedDeleteInformation = true
    //是否是正面
    private var isFront = true
    //正面照
    private var imgFrontUrl = ""
    //背面照
    private var imgBackUrl = ""
    //图片选择
    lateinit var pickMedia: ActivityResultLauncher<PickVisualMediaRequest>

    constructor(stepItem: JSONObject): this(){
        this.stepItem = stepItem
        eventRemark = stepItem.optString("stepTitle")
    }

    override fun getObremponRootView(inflater: LayoutInflater): View {
        binding = ObremponAuthStepOcrFragmentBinding.inflate(inflater)
        return binding.root
    }

    override fun initObremponView() {
        initObremponOcrTypeTitleText()
        initObremponOcrUploadCreditLimitAddTipsText()
        initObremponOcrUploadCreditLimitApprovedTipsText()
    }

    override fun initObremponListener() {
        //切换是否选中删除个人信息
        binding.deleteInformationTipsLayout.setOnClickListener {
            isSelectedDeleteInformation = !isSelectedDeleteInformation
            showObremponDeleteInformationTips()
        }
        //选择类型
        binding.ocrChooseTypeLayout.setOnClickListener {
            showObremponCheckTypePopupwindow(binding.ocrChooseTypeLayout)
        }
        //正面
        binding.ocrUploadFrontLayout.setOnClickListener {
            isFront = true
            if (selectTypeItem != null){
                val eventRemark = "${selectTypeItem?.optString("ocrType")} Front"
                showAuthStepOcrPhotoDialog(eventRemark)
            }
        }
        //背面
        binding.ocrUploadBackLayout.setOnClickListener {
            isFront = false
            if (selectTypeItem != null){
                val eventRemark = "${selectTypeItem?.optString("ocrType")} Back"
                showAuthStepOcrPhotoDialog(eventRemark)
            }
        }
        //提交
        binding.buttonOcrNext.setOnClickListener {
            if (selectTypeItem == null){
                return@setOnClickListener
            }
            var ocrType = selectTypeItem!!.optString("ocrType")
            if (!isObremponAllowSubmit()){
                showErrorTipsDialog(getString(R.string.obrempon_dialog_tips_submit_error),ocrType)
                return@setOnClickListener
            }
            //如果是选举卡类型，需要按照身份证类型上传
            if (ocrType == "ELECTIONCARD"){
                ocrType = "IDCARD"
            }
            val params = JSONObject().addCommonParams().apply {
                put("path", ObremponApiPath.OBREMPON_PATH.OBREMPON_API_OCR_INFO_PATH)
                put("cardType",ocrType)//证件类型（PASSPORT、IDCARD、DRIVING、FACE、NONE）
            }
            if (imgFrontUrl.isNotEmpty()){
                params.put("cardImgUrl",imgFrontUrl)//证件图片正面
            }
            if (imgBackUrl.isNotEmpty()){
                params.put("cardBackImgUrl",imgBackUrl)//证件图片反面
            }

            //选中删除信息提示
            if (isSelectedDeleteInformation){
                showObremponDeleteInformationTipsDialog()
                launch(Dispatchers.Main){
                    delay(1500)
                    submitObremponOCRDataAction(params)
                }
            } else {
                submitObremponOCRDataAction(params)
            }
            addEventPointRequestAction(String.format(ObremponEventPointType.CLICK.OBREMPON_CLICK_STEP_OCR_XX_NEXT,ocrType),"")
        }

        // 1-注册图库组件
        pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
            if (uri != null) {
                // 图片处理
                ImageConvert.covert(context = requireContext(), uri = uri) { localPath, bitmap ->
                    if (localPath != null){
                        ObremponLogger.e(">>>>>>>album>>>>>>>>>>$localPath")
                        uploadObremponOCRImageAction(localPath)
                    }
                }
            } else {
                ObremponLogger.e("No media selected")
            }
        }
    }

    override fun takeObremponData() {
        addEventPointRequestAction(String.format(ObremponEventPointType.PAGE.OBREMPON_PAGE_STEP_OCR_XX_START,eventRemark))
        ocrTypeList.clear()
        var ocrTypeSize = typeTitleList.size
        //是否支持选择不传证件照
        if (!ObremponConfigsHelper.isShowOcrNoDocuments()){
            ocrTypeSize -= 1
        }
        for (i in 0..< ocrTypeSize){
            val item = JSONObject()
            item.put("iconId",typeTitleList[i].split(",")[0])
            item.put("title",typeTitleList[i].split(",")[1])
            item.put("ocrType",typeTitleList[i].split(",")[2])
            item.put("isSelect",i == 0)
            if (i == 0){
                selectTypeItem = item
            }
            ocrTypeList.add(item)
        }
        //设置显示Ocr类型
        showObremponAuthStepOcrTypeViews()
    }

    private fun initObremponOcrTypeTitleText(){
        val showOcrTypeTitle = getString(R.string.obrempon_auth_step_ocr_select_type)
        val ocrTypeSpannable = SpannableString(showOcrTypeTitle)
        ocrTypeSpannable.setSpan(ForegroundColorSpan(getColor(R.color.color_ffff4d3e)), showOcrTypeTitle.length - 1, showOcrTypeTitle.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        binding.textOcrTypeTitle.text = ocrTypeSpannable
    }

    private fun initObremponOcrUploadCreditLimitAddTipsText(){
        val creditLimitAmount = stepItem?.optString("creditLimitAmount")
        val showTipsKey1 = String.format(getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_add_tips_key1),creditLimitAmount)
        val showTipsKey2 = getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_add_tips_key2)
        val showTipsText = String.format(getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_add_tips),showTipsKey1,showTipsKey2)
        val startTipsIndex1 = showTipsText.indexOf(showTipsKey1)
        val startTipsIndex2 = showTipsText.indexOf(showTipsKey2)
        val creditLimitTipsSpannable = SpannableString(showTipsText)
        creditLimitTipsSpannable.setSpan(ForegroundColorSpan(getColor(R.color.color_ffff5811)), startTipsIndex1, startTipsIndex1 + showTipsKey1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        creditLimitTipsSpannable.setSpan(ForegroundColorSpan(getColor(R.color.color_ffff5811)), startTipsIndex2, startTipsIndex2 + showTipsKey2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //加粗
        creditLimitTipsSpannable.setSpan(StyleSpan(Typeface.BOLD), startTipsIndex1, startTipsIndex1 + showTipsKey1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        creditLimitTipsSpannable.setSpan(StyleSpan(Typeface.BOLD), startTipsIndex2, startTipsIndex2 + showTipsKey2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        binding.textOcrUploadCreditLimitAddTips.text = creditLimitTipsSpannable
    }

    private fun initObremponOcrUploadCreditLimitApprovedTipsText(){
        val showApprovedKey1 = getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_approved_tips_key1)
        val showApprovedKey2 = getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_approved_tips_key2)
        val showApprovedText = String.format(getString(R.string.obrempon_auth_step_ocr_upload_credit_limit_approved_tips),showApprovedKey1,showApprovedKey2)
        val startApprovedIndex1 = showApprovedText.indexOf(showApprovedKey1)
        val startApprovedIndex2 = showApprovedText.indexOf(showApprovedKey2)
        val approvedTipsSpannable = SpannableString(showApprovedText)
        approvedTipsSpannable.setSpan(ForegroundColorSpan(getColor(R.color.color_ffff5811)), startApprovedIndex1, startApprovedIndex1 + showApprovedKey1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        approvedTipsSpannable.setSpan(ForegroundColorSpan(getColor(R.color.color_ffff5811)), startApprovedIndex2, startApprovedIndex2 + showApprovedKey2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //加粗
        approvedTipsSpannable.setSpan(StyleSpan(Typeface.BOLD), startApprovedIndex1, startApprovedIndex1 + showApprovedKey1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        approvedTipsSpannable.setSpan(StyleSpan(Typeface.BOLD), startApprovedIndex2, startApprovedIndex2 + showApprovedKey2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        binding.textOcrUploadCreditLimitApprovedTips.text = approvedTipsSpannable
    }

    private fun showObremponDeleteInformationTips(){
        when(isSelectedDeleteInformation){
            true -> {
                binding.imgSelectDeleteInformation.setImageResource(R.mipmap.obrempon_auth_step_ocr_delete_information_selected_icon)
            }
            else -> {
                binding.imgSelectDeleteInformation.setImageResource(R.mipmap.obrempon_auth_step_ocr_delete_information_normal_icon)
            }
        }
    }

    /**
     * 选择选项
     */
    private fun showObremponCheckTypePopupwindow(view: View){
        if (ocrTypePopupwindow == null){
            ocrTypePopupwindow = ObremponOcrTypePopupwindow(requireContext())
            ocrTypePopupwindow?.setWindowWidth(view.width + ObremponDensityUtil.dp2px(10f))
            ocrTypePopupwindow?.setSelectItemListener(object : ObremponOcrTypePopupwindow.IItemClickListener {
                //完成
                override fun onConfirmAction(data: JSONObject?) {
                    if (data != null){
                        selectTypeItem = data
                        showObremponAuthStepOcrTypeViews()
                    }
                }
                //关闭监听
                override fun onDismissListener() {
                }
            })
            ocrTypePopupwindow?.show(view, binding.root)
            ocrTypePopupwindow?.setBrandList(ocrTypeList)
            return
        }
        ocrTypePopupwindow?.show(view, binding.root)
    }

    /**
     * 显示Ocr类型
     */
    private fun showObremponAuthStepOcrTypeViews(){
        if (selectTypeItem == null){
            return
        }
        binding.textOcrType.text = selectTypeItem?.optString("title")
        binding.textShowOcrType.text = selectTypeItem?.optString("title")
        binding.textShowOcrType.visibility = View.VISIBLE

        imgFrontUrl = ""
        imgBackUrl = ""
        isSelectedDeleteInformation = true
        showObremponDeleteInformationTips()

        //选择上传证件照激励文案，只有选择 “No documents” 才显示
        binding.ocrUploadCreditLimitAddTipsLayout.visibility = View.GONE
        //审核通过率提示文案
        binding.ocrUploadCreditLimitApprovedTipsLayout.visibility = View.VISIBLE
        //正面
        binding.ocrUploadFrontLayout.visibility = View.VISIBLE
        binding.imgOcrTypeUploadFront.setImageResource(R.mipmap.obrempon_auth_step_ocr_upload_front_icon)
        //反面
        binding.ocrUploadBackLayout.visibility = View.VISIBLE
        binding.imgOcrTypeUploadBack.setImageResource(R.mipmap.obrempon_auth_step_ocr_upload_back_icon)

        val ocrType = selectTypeItem!!.optString("ocrType")
        when(ocrType){
            "IDCARD" -> {
                binding.textOcrTypeUploadFront.text = getString(R.string.obrempon_auth_step_ocr_type_id_card_front_hint)
                binding.textOcrTypeUploadBack.text = getString(R.string.obrempon_auth_step_ocr_type_id_card_back_hint)
            }
            "PASSPORT" -> {
                binding.textOcrTypeUploadFront.text = getString(R.string.obrempon_auth_step_ocr_type_passport_hint)
                binding.ocrUploadBackLayout.visibility = View.GONE
            }
            "DRIVING" -> {
                binding.textOcrTypeUploadFront.text = getString(R.string.obrempon_auth_step_ocr_type_driving_license_front_hint)
                binding.textOcrTypeUploadBack.text = getString(R.string.obrempon_auth_step_ocr_type_driving_license_back_hint)
            }
            "ELECTIONCARD" -> {
                binding.textOcrTypeUploadFront.text = getString(R.string.obrempon_auth_step_ocr_type_election_card_front_hint)
                binding.textOcrTypeUploadBack.text = getString(R.string.obrempon_auth_step_ocr_type_election_card_back_hint)
            }
            else -> {
                binding.ocrUploadCreditLimitAddTipsLayout.visibility = View.VISIBLE
                binding.textShowOcrType.visibility = View.GONE
                binding.ocrUploadFrontLayout.visibility = View.GONE
                binding.ocrUploadBackLayout.visibility = View.GONE
                binding.ocrUploadCreditLimitApprovedTipsLayout.visibility = View.GONE
            }
        }
    }

    /**
     * 相机、相册
     */
    private fun showAuthStepOcrPhotoDialog(eventRemark: String){
        if (photoDialog == null){
            photoDialog = ObremponPhotoDialog(requireContext(),object : ObremponPhotoDialog.IDialogCallback{
                override fun openCamera() {
                    addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_CAMERA,eventRemark)
                    if (EasyPermissions.hasPermissions(requireContext(), Manifest.permission.CAMERA)){
                        openObremponAuthStepOcrCamera()
                    } else {
                        EasyPermissions.requestPermissions(this@ObremponAuthStepOcrFragment, getString(R.string.obrempon_auth_step_ocr_camera_reason),1001,Manifest.permission.CAMERA)
                    }
                }
                override fun openAlbum() {
                    addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_ALBUM,eventRemark)
                    openObremponAuthStepOcrAlbum()
                }
            })
            photoDialog?.setCancelable(true)
            photoDialog?.setCanceledOnTouchOutside(true)
        }
        photoDialog?.setEventRemark(eventRemark)
        photoDialog?.show()
    }

    /**
     * Ocr拍照
     */
    private val takePhotoResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
        when (result.resultCode) {
            Activity.RESULT_OK -> {
                ObremponLogger.e(">>>>>>onActivityResult: data = " + result.data)
                val imgLocalPath = result.data!!.getStringExtra("imgLocalPath").toString()
                val imgUrl = result.data!!.getStringExtra("imgUrl").toString()
                showObremponOCRUploadImageSuccess(imgLocalPath,imgUrl)
            }
        }
    }

    /**
     * 打开相册
     */
    private fun openObremponAuthStepOcrAlbum(){
        pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
    }

    /**
     * 打开相机
     */
    private fun openObremponAuthStepOcrCamera(){
        takePhotoResultLauncher.launch(Intent(context, ObremponCameraOcrAct::class.java))
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        // 进一步使用 EasyPermissions 处理后续结果
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    /**
     * 用户点击同意授权后会回调该方法
     */
    override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
        perms.forEach {
            addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_PERMISSION_SYSTEM_AGREE, it)
        }
        if (requestCode == 1001){
            openObremponAuthStepOcrCamera()
        }
    }

    /**
     * 用户点击拒绝授权后会回调该方法
     */
    override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
        perms.forEach {
            addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_PERMISSION_SYSTEM_DENY, it)
        }
        // 如果申请的权限中有任何一个权限存在 永久拒绝 的情况
        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
            // 设置 引导用户前往设置界面 自行设置权限的引导对话框
            AppSettingsDialog.Builder(this)
//                .setTitle("需要手动设置权限")
//                .setRationale("存在永久拒绝的权限 , 需要手动前往设置界面为应用进行授权")
//                .setPositiveButton("前往设置界面")
//                .setNegativeButton("不使用该功能")
                .build().show()
        }
    }

    override fun onRationaleAccepted(requestCode: Int) {
        ObremponLogger.e("onRationaleAccepted, code: $requestCode")
    }

    override fun onRationaleDenied(requestCode: Int) {
        ObremponLogger.e("onRationaleDenied, code: $requestCode")
    }

    @Deprecated("Deprecated in Java")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == 1001){
            // 判断五种权限是否申请成功
            val hasPermissions = EasyPermissions.hasPermissions(requireContext(), Manifest.permission.CAMERA)
            if (hasPermissions){
                openObremponAuthStepOcrCamera()
            }
        }
    }
    /**
     * 图片上传成功
     */
    fun showObremponOCRUploadImageSuccess(imgPath: String, imgUrl: String) {
        if (selectTypeItem == null){
            return
        }
        when(isFront){
            true -> {
                imgFrontUrl = imgUrl
                ObremponImageUtil.instance.loadImageUrl(requireContext(),binding.imgOcrTypeUploadFront,imgPath)
                val eventRemark = "${selectTypeItem?.optString("ocrType")} Front $$$imgUrl"
                addEventPointRequestAction(ObremponEventPointType.FORM.OBREMPON_FORM_STEP_OCR_UPLOAD_URL,eventRemark)
            }
            else -> {
                imgBackUrl = imgUrl
                ObremponImageUtil.instance.loadImageUrl(requireContext(),binding.imgOcrTypeUploadBack,imgPath)
                val eventRemark = "${selectTypeItem?.optString("ocrType")} Back $$$imgUrl"
                addEventPointRequestAction(ObremponEventPointType.FORM.OBREMPON_FORM_STEP_OCR_UPLOAD_URL,eventRemark)
            }
        }
    }

    /**
     * 检查是否填写完整
     * 当且仅当 isMust=”NO“为非必填
     */
    private fun isObremponAllowSubmit(): Boolean{
        //没有选择类型
        if (selectTypeItem == null){
            return false
        }
        val ocrType = selectTypeItem?.optString("ocrType")
        if (ocrType == "NONE"){
            return true
        }
        if (imgFrontUrl.isEmpty()){
            return false
        }
        if (imgBackUrl.isEmpty() && (ocrType == "IDCARD" || ocrType == "DRIVING" || ocrType == "ELECTIONCARD")){
            return false
        }
        return true
    }

    /**
     * 提交成功提示
     */
    private fun showObremponDeleteInformationTipsDialog(){
        val sendSuccessDialog = ObremponSubmitSuccessDialog(requireContext())
        sendSuccessDialog.setCancelable(true)
        sendSuccessDialog.setCanceledOnTouchOutside(false)
        sendSuccessDialog.show()
        sendSuccessDialog.setTipsSuccessText(getString(R.string.obrempon_auth_step_ocr_submit_success_tips))
        launch(Dispatchers.Main){
            delay(1500)
            sendSuccessDialog.dismiss()
        }
    }

    /**
     * 图片上传
     */
    private fun uploadObremponOCRImageAction(imgPath: String){
        showObremponLoading(isTOuchOut = false, isCancel = false)
        HttpHelper.setTag(this)
        HttpHelper.upload(imgPath,object : OnUpdateListener<UpdateImageApi.ImageBean> {
            override fun onUpdateProgressChange(progress: Int) {
                ObremponLogger.e(">onUpdateProgressChange>>>>>>>>>>>>>>>>$progress")
            }

            override fun onUpdateFail(throwable: Throwable) {
                ObremponLogger.e(">throwable>>>>>>>>>>>>>>>>")
            }

            override fun onUpdateSuccess(result: UpdateImageApi.ImageBean) {
                ObremponLogger.e(">onUpdateSuccess>>>>>>>>>>>>>>>>${result.obj.url}")
                when(result.code){
                    0 -> {
                        val imgUrl = result.obj.url
                        showObremponOCRUploadImageSuccess(imgPath,imgUrl)
                    }
                    else -> {
                        showObremponToast(result.msg)
                    }
                }
            }

            override fun onUpdateEnd(api: IRequestApi) {
                ObremponLogger.e(">onUpdateEnd>>>>>>>>>>>>>>>>")
                hideObremponLoading()
            }
        })
    }

    /**
     * 提交
     */
    private fun submitObremponOCRDataAction(params: JSONObject){
        val act = getAct() as ObremponAuthStepsAct
        act.onObremponAuthStepSubmitAction(params)
    }

    override fun onDestroy() {
        super.onDestroy()
        HttpHelper.cancelTag(this)
        addEventPointRequestAction(String.format(ObremponEventPointType.PAGE.OBREMPON_PAGE_STEP_OCR_XX_END,eventRemark))
    }
}